using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using DreidelGame.ObjectModel;
using Microsoft.Xna.Framework.Graphics;
using DreidelGame.Interfaces;

namespace DreidelGame
{
    /// <summary>
    /// Responsible for presenting the player score on the screen
    /// </summary>
    public class ScoreManager : DrawableGameComponent
    {
        private const int k_PlayerScoreIncrement = 1;
        private const int k_DefaultPlayerScore = 0;
        private const string k_DrawText = "Player Score: {0}";

        private int m_CurrPlayerScore;
        private eDreidelLetters m_PlayerChosenLetter;
        private string m_Text = String.Empty;

        /// <summary>
        /// Property that gets/sets the letter that the player chose
        /// </summary>
        public eDreidelLetters      PlayerChosenLetter
        {
            get { return m_PlayerChosenLetter; }

            set { m_PlayerChosenLetter = value; }
        }

        /// <summary>
        /// Gets/sets the player score
        /// </summary>
        public int      PlayerScore
        {
            get { return m_CurrPlayerScore; }

            set
            {
                m_CurrPlayerScore = value;
                m_Text = String.Format(k_DrawText, m_CurrPlayerScore);
            }
        }

        /// <summary>
        /// CTOR. inits a new instance
        /// </summary>
        /// <param name="i_Game">The hosting game</param>
        public ScoreManager(Game i_Game)
            : base(i_Game)
        {
            m_PlayerChosenLetter = eDreidelLetters.None;

            PlayerScore = k_DefaultPlayerScore;
        }

        /// <summary>
        /// Draws the players score on the screen
        /// </summary>
        /// <param name="i_GameTime">A snapshot of the games time</param>
        public override void    Draw(GameTime i_GameTime)
        {
            base.Draw(i_GameTime);

            Game.Window.Title = m_Text;
        }

        /// <summary>
        /// Catch a finished spinning event raised by a dreidel and updates the players score 
        /// in case the dreidel current side letter matches the letter that the player chose        
        /// </summary>
        /// <param name="i_Dreidel">The dreidel that raised the event</param>
        public void     Dreidel_FinishedSpinning(IDreidel i_Dreidel)
        {
            if (i_Dreidel.DreidelFrontLetter.Equals(m_PlayerChosenLetter))
            {
                PlayerScore = PlayerScore + i_Dreidel.DreidelScore;
            }
        }
    }
}
